package com.csii.security;

import com.csii.user.entity.SysUser;
import com.csii.user.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

/**
 * 通过openId获取用户信息和权限资源
 * @Auther: ian
 */
@Component("openIdUserDetailsService") // 一定不要少了
public class OpenIdUserDetailsService extends AbstractUserDetailsService {

    @Autowired
    private ISysUserService sysUserService;
    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public SysUser findSysUser(String openId) {
        //根据openId从缓存中拿出userid
        String userId = (String) redisTemplate.opsForValue().get(openId);
        if (userId == null){
            return null;
        }
        return sysUserService.getById(userId);
    }

}